package com.zaiboot.examples.login;

import android.os.Bundle;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity {

	/**
	 * Obtains a string from a EditText control.
	 * 
	 * @param id : The id of the control to use
	 * @return : The string inside the EditText control
	 */
	private String ObtainTextFromEditText(int id) {
			String resultingString = "";
			View viewControl =  this.findViewById(id);
			if	( viewControl != null) {
				EditText txtControl = null;
				try {
					txtControl =(EditText)viewControl;	
				} catch (ClassCastException e) {
					return resultingString;
				}
				resultingString = txtControl.getText().toString();
			}
			return resultingString ;
	}
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_login, menu);
        return true;
    }
    
    public void LoginClick(View view) {
    	
    	String userName= ObtainTextFromEditText(R.id.EditUserName);
    	String password= ObtainTextFromEditText(R.id.EditPassword);
    	TextView TextResult;
    	TextResult =  (TextView)this.findViewById(R.id.TextResult);
    	if (userName.equals("a") && password.equals("a") ){
    		//User valid
    		TextResult.setText(R.string.login_correct);
    		TextResult.setTextColor(Color.GREEN);
    	}else {
			//User invalid
    		TextResult.setText(R.string.login_failed);
    		TextResult.setTextColor(Color.RED);
		}
    	
    	
    	
    	
	}
}
                                      